#include "mouvement.h"

static int *next_bloc(int ac[2], int *ret, s_case *path)
{
    while (path && ((path->y != ac[0]) || (path->x != ac[1])))
        path = path->next;

    path = path->next;
    ret[0] = path->y;
    ret[1] = path->x;

    return (ret);
}

/**
** @brief Update the position of the ennemies
**
** @param Object structure
*/
void update_all_pos(s_object *object)
{
    s_enn_list  *l = NULL;
    int         *ret;
    int         tmp[2];
    int         *save;

    l = object->enn_list;
    while (l)
    {
        tmp[0] = l->pos[0];
        tmp[1] = l->pos[1];

        ret = malloc(2 * sizeof (int));
        save = next_bloc(l->pos, ret, l->pathfinding);

        l->pos[0] = save[0];
        l->pos[1] = save[1];

        l->prev[0] = tmp[0];
        l->prev[1] = tmp[1];

        free(ret);
        l = l->next;
    }
}
